<?php

namespace Database\Seeders;

use App\Models\Category;
use App\Models\Event;
use App\Models\Tag;
use App\Models\User;
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use PHPUnit\Event\EventFacadeIsSealedException;

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     */
    public function run(): void
    {
        // User::factory(10)->create();

//        User::factory()->create([
//            'name' => 'Test User',
//            'email' => 'test@example.com',
//        ]);
        User::insert([
            ["name"=>"admin1","email"=>"admin1@email.com","password"=>Hash::make("admin1pass"),"role"=>"ADMIN"],
            ["name"=>"admin2","email"=>"admin2@email.com","password"=>Hash::make("admin2pass"),"role"=>"ADMIN"],
            ["name"=>"user1","email"=>"user1@email.com","password"=>Hash::make("user1pass",),"role"=>"USER"],
            ["name"=>"user2","email"=>"user2@email.com","password"=>Hash::make("user2pass",),"role"=>"USER"],
            ["name"=>"user3","email"=>"user3@email.com","password"=>Hash::make("user3pass",),"role"=>"USER"],
        ]);

        Category::insert([
            ["name"=>"Meeting"],
            ["name"=>"Music"],
            ["name"=>"Sport"],
            ["name"=>"Research"],
            ["name"=>"Entertainment"],
        ]);

        Tag::insert([
            ["name"=>"tag1"],
            ["name"=>"tag2"],
            ["name"=>"tag3"],
            ["name"=>"tag4"],
            ["name"=>"tag5"],
            ["name"=>"tag6"],
            ["name"=>"tag7"],
            ["name"=>"tag8"],
        ]);

        $time = now()->subDays(10);
        for($i=1;$i<=38;$i++){
            $hour = fake()->numberBetween(9,15);
            $st = $time->copy()->setHour($hour)->setMinute(0)->setSecond(0);
            $creator_id = fake()->numberBetween(1,2);
            $event = Event::create([
                "title"=>"Event $i",
                "description"=>"Event $i description",
                "type"=>fake()->randomElement(["PUBLIC","PRIVATE"]),
                "start_at"=>$st,
                "end_at"=>$st->copy()->addHours(fake()->numberBetween(2,3)),
                "location"=>"Location $i",
                "creator_id"=> $creator_id,
                "category_id"=>fake()->numberBetween(1,5),
                "capacity"=>fake()->numberBetween(2,10)*10,
            ]);
            $event->tags()->attach(fake()->randomElements([1,2,3,4,5,6,7,8],fake()->numberBetween(1,5)));
            DB::table("event_attendee")->insert([
                "event_id"=>$event->id,
                "user_id"=>$creator_id,
            ]);
            $time->addDays(fake()->numberBetween(1,3));
        }

    }
}
